#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 标量运算，单个元素运算
# 向量运算，多个元素运算，如向量加法、向量减法、向量点乘、向量叉乘、向量长度、向量单位化
# 矩阵运算，多个向量运算，如矩阵乘法、矩阵转置、矩阵求逆、矩阵求秩、矩阵求特征值、矩阵求解线性方程组等
# 张量运算，多个矩阵运算，如张量乘法、张量转置、张量求和、张量求差、张量求积、张量求导、张量求和、张量求商等

import numpy as np

# 标量运算
# a = 2
# b = 3
# c = a + b
# print(c)  # 5


# 向量运算
# a = np.array([1, 2, 3])
# b = np.array([4, 5, 6])
# c = a + b
# print(c)  # [5 7 9]

# import matplotlib.pyplot as plt
# img = plt.imread('static/1.jpg')
# print(img.ndim) # 3
# print(img.shape) # (480, 640, 3)
# print(img.size) # 1296000
# print(img.dtype) # uint8

# 将可迭代对象转换为numpy数组
# a = [1, 2, 3]
# b = np.array(a)
# print(b)  # [1 2 3]

# 等差数列
# start:起始值
# stop:终止值
# step:步长
# num:元素个数
# a = np.arange(1, 10, 2)
# print(a)  # [1 3 5 7 9]
# a = np.linspace(start=1, stop=10, num=10)
# print(a)


# print(np.ones(shape=(3, 3))) # 全1数组
# print(np.zeros(shape=(3, 3))) # 全0数组
# print(np.zeros_like(np.ones(shape=(3, 3)))) # 全0数组，与ones_like()函数的作用相同
# print(np.empty(shape=(3, 3))) # 未初始化数组
# print(np.eye(N=3)) # 单位矩阵
# print(np.random.rand(3, 3)) # 随机数组
# print(np.random.randn(3, 3)) # 标准正态分布数组

# 对角矩阵
# a = np.diag([1, 2, 3])
# print(a)
# [[1 0 0]
# 单位矩阵
# a = np.eye(3)
# print(a)

# 按列的顺序进行堆叠
# a = np.vstack((np.array([1, 2, 3]), np.array([4, 5, 6])))
# print(a)


# 按行的顺序进行堆叠
# a = np.hstack((np.array([1, 2, 3]), np.array([4, 5, 6])))
# print(a)

# 矩阵乘法
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
c = np.dot(a, b)
print(c)

# 内积：两个向量的点积
# a = np.array([1, 2, 3])
# b = np.array([4, 5, 6])
# c = np.dot(a, b)
# print(c)  # 32


